home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / guigfxlib / examples / plasma / source / timer.asm < prev    next >
Assembly Source File  |  1999-01-01  |  2KB  |  118 lines

  1.  
  2.         section    text
  3.  
  4.     
  5.         XDEF    _timerstart
  6.         XDEF    _timerstop
  7.  
  8.  
  9.         include    "devices/timer.i"
  10.         include    "lvo/timer_lib.i"
  11.         include    "lvo/exec_lib.i"
  12.         include    "exec/memory.i"
  13.  
  14. ;====================================================================
  15. ;--------------------------------------------------------------------
  16. ;
  17. ;    handle = timerstart()
  18. ;    d0
  19. ;        initialisiert und startet den Timer.
  20. ;
  21. ;    millisec = timerstop(handle)
  22. ;    d0              d0
  23. ;
  24. ;        liest den Timer und liefert
  25. ;        die Anzahl der Tausendstel Sekunden.
  26. ;
  27. ;--------------------------------------------------------------------
  28.  
  29.     STRUCTURE    mytimer,0
  30.         APTR    timer_base
  31.         STRUCT    timer_request,IOTV_SIZE
  32.         DOUBLE    timer_val1
  33.         DOUBLE    timer_val2
  34.     LABEL        timer_SIZEOF
  35.  
  36. ;--------------------------------------------------------------------
  37.  
  38. _timerstart:    movem.l    d1-a6,-(a7)
  39.  
  40.         move.l    4.w,a6
  41.         moveq    #timer_SIZEOF,d0
  42.         moveq    #MEMF_ANY,d1
  43.         jsr    (_LVOAllocVec,a6)
  44.         tst.l    d0
  45.         beq.b    .exit
  46.  
  47.         move.l    d0,a5
  48.  
  49.         clr.l    (timer_base,a5)
  50.  
  51.         lea    (timer_name,pc),a0
  52.         lea    (timer_request,a5),a1
  53.         moveq    #0,d0
  54.         moveq    #0,d1
  55.         jsr    (_LVOOpenDevice,a6)
  56.         tst.b    d0
  57.         bne.b    .fail
  58.  
  59.         move.l    (timer_request+IO_DEVICE,a5),a6
  60.         move.l    a6,(timer_base,a5)
  61.         lea    (timer_val1,a5),a0
  62.         jsr    (_LVOReadEClock,a6)
  63.         
  64.         move.l    a5,d0
  65.         bra.b    .exit
  66.  
  67. .fail        move.l    a5,a1
  68.         jsr    (_LVOFreeVec,a6)
  69.         moveq    #0,d0
  70.  
  71. .exit        movem.l    (a7)+,d1-a6
  72.         rts
  73.  
  74.  
  75. ;--------------------------------------------------------------------
  76.  
  77. _timerstop:    movem.l    d1-a6,-(a7)
  78.  
  79.         move.l    d0,a5
  80.  
  81.         move.l    (timer_base,a5),d0
  82.         beq.b    timer_error
  83.         move.l    d0,a6
  84.  
  85.         lea    (timer_val2,a5),a0
  86.         jsr    (_LVOReadEClock,a6)
  87.         move.l    d0,d4            ; Timer-Frequenz [Hz]
  88.  
  89.         movem.l    (timer_val1,a5),d2/d3
  90.         movem.l    (timer_val2,a5),d0/d1
  91.         sub.l    d3,d1
  92.         subx.l    d2,d0
  93.  
  94.         mulu.l    #1000,d0:d1
  95.         divu.l    d4,d0:d1        ; tausendstel Sekunden
  96.         move.l    d1,d2
  97.  
  98.         lea    (timer_request,a5),a1
  99.         move.l    4.w,a6
  100.         jsr    (_LVOCloseDevice,a6)
  101.  
  102.         move.l    a5,a1
  103.         move.l    4.w,a6
  104.         jsr    (_LVOFreeVec,a6)
  105.  
  106.         move.l    d2,d0
  107.  
  108. timer_error    movem.l    (a7)+,d1-a6
  109.         rts
  110.  
  111. ;--------------------------------------------------------------------
  112.  
  113. timer_name    dc.b    "timer.device",0
  114.         even
  115.  
  116. ;====================================================================
  117.  
  118.